package com.atguigu.gmall.file;

import org.csource.fastdfs.*;
import org.springframework.util.ClassUtils;

import java.io.IOException;

/**
 * description:
 * create by sxy 2021/5/10
 */
public class FileUploadDemo {
    public static void main(String[] args) throws Exception {

//E:\workspaceidea\java201116BJ\gmall-201116suxniaoyao\gmall-parent\service\service-product\src\main\resources\fdfs_client.conf
        String path = ClassUtils.getDefaultClassLoader().
                getResource("fdfs_client.conf").getPath();
        //0 配置跟踪器的ip port
        ClientGlobal.init(path);
        //创建traxkerclient客户端
        TrackerClient trackerClient = new TrackerClient();

        //2连接trackerserver端
        TrackerServer trackerServer = trackerClient.getConnection();
        //3创建storage客户端
        StorageServer storageServer = null;
        StorageClient1 storageClient1 = new StorageClient1(trackerServer, storageServer);

        //3 上传文件
        String fileId = storageClient1.upload_file1("D:\\元气壁纸缓存\\img\\38f89705dbbe98ce3aca72577299e2df.jpg"
                , "jpg", null);
        System.out.println("fileId = " + fileId);
        //http://192.168.6.131:8080/group1/M00/00/00/wKgGg2CZRmOAFOYFABb6is_KHqs871.jpg
    }
}
